const util = require('../../utils/util.js')
Page({
  data: {
  	//这个数组是picker每一列的数据,multiArray[[],[],[]]。例如，multiArray[0]就是第一列的数据
    multiArray: [
      [
        {
          "okr_id": 1,
          "name": "全部种类"
        },
        {
          "okr_id": 2,
          "name": "企业"
        },
        {
          "okr_id": 3,
          "name": "私人"
        }
      ],
      [
        {
          "okr_id": 6,
          "name": "全部类型"
        }
      ],
      [
        {
          "okr_id": 24,
          "name": "全部状态"
        },
        {
          "okr_id": 25,
          "name": "待确认"
        },
        {
          "okr_id": 26,
          "name": "进行中"
        },
        {
          "okr_id": 27,
          "name": "已完成"
        },
        {
          "okr_id": 28,
          "name": "已逾期"
        }
      ]
    ],
    //数据源，这里是通过接口获取的。为方便测试，直接写在这里。实际过程中可以调接口，再setData
    //注意格式，三级结构，这里id是okr_id。低一级放在高一级的nextList中，每一级的字段名是一样的（range-key设置为
    //‘name’）。后台的数据返回必须是这种格式的。
    objectArrayDiseaseData: [
      {						 
        "okr_id": 1,			//第一级
        "name": "全部种类",
        "nextList": [
          {
            "okr_id": 6,		//第二级
            "name": "全部类型",
            "nextList": [
              {
                "okr_id": 24,	//第三级
                "name": "全部状态"
              },
              {
                "okr_id": 25,
                "name": "待确认"
              },
              {
                "okr_id": 26,
                "name": "进行中"
              },
              {
                "okr_id": 27,
                "name": "已完成"
              },
              {
                "okr_id": 28,
                "name": "已逾期"
              }
            ]
          }
        ]
      },
      {
        "okr_id": 2,
        "name": "企业",
        "nextList": [
          {
            "okr_id": 6,		//第二级
            "name": "全部类型",
            "nextList": [
              {
                "okr_id": 24,	//第三级
                "name": "全部状态"
              },
              {
                "okr_id": 25,
                "name": "待确认"
              },
              {
                "okr_id": 26,
                "name": "进行中"
              },
              {
                "okr_id": 27,
                "name": "已完成"
              },
              {
                "okr_id": 28,
                "name": "已逾期"
              }
            ]
          },
          {
            "okr_id": 7,
            "name": "公司",
            "nextList": [
              {
                "okr_id": 24,	//第三级
                "name": "全部状态"
              },
              {
                "okr_id": 25,
                "name": "待确认"
              },
              {
                "okr_id": 26,
                "name": "进行中"
              },
              {
                "okr_id": 27,
                "name": "已完成"
              },
              {
                "okr_id": 28,
                "name": "已逾期"
              }
            ]
          },
          {
            "okr_id": 8,
            "name": "部门",
            "nextList": [
              {
                "okr_id": 24,	//第三级
                "name": "全部状态"
              },
              {
                "okr_id": 25,
                "name": "待确认"
              },
              {
                "okr_id": 26,
                "name": "进行中"
              },
              {
                "okr_id": 27,
                "name": "已完成"
              },
              {
                "okr_id": 28,
                "name": "已逾期"
              }
            ]
          },
          {
            "okr_id": 9,
            "name": "个人",
            "nextList": [
              {
                "okr_id": 24,	//第三级
                "name": "全部状态"
              },
              {
                "okr_id": 25,
                "name": "待确认"
              },
              {
                "okr_id": 26,
                "name": "进行中"
              },
              {
                "okr_id": 27,
                "name": "已完成"
              },
              {
                "okr_id": 28,
                "name": "已逾期"
              }
            ]
          }
        ]
      },
      {
        "okr_id": 3,
        "name": "私人",
        "nextList": [
          {
            "okr_id": 6,		//第二级
            "name": "全部类型",
            "nextList": [
              {
                "okr_id": 24,	//第三级
                "name": "全部状态"
              },
              {
                "okr_id": 25,
                "name": "待确认"
              },
              {
                "okr_id": 26,
                "name": "进行中"
              },
              {
                "okr_id": 27,
                "name": "已完成"
              },
              {
                "okr_id": 28,
                "name": "已逾期"
              }
            ]
          }
        ]
      }
    ],
    //这个数组是指每一列所选值的下标index。例如，multiIndex: [0, 0, 0]是指第一列选第一个，第二列选第一个，第三列选第一个
    multiIndex: [0, 0, 0],
 
    date: '2021-01-01',//默认起始时间  
    date2: '2021-04-01'//默认结束时间 
 
  },

  // 时间段选择  
  bindDateChange(e) {
    let that = this;
    console.log(e.detail.value)
    that.setData({
    date: e.detail.value,
    })
  },
  bindDateChange2(e) {
    let that = this;
    console.log(e.detail.value)
    that.setData({
    date2: e.detail.value,
    })
  },


  //这个事件并没有什么用，因为这里的value并不是我们想要的id。而且我们想要改变选项即改变所选id。
  bindMultiPickerChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      multiIndex: e.detail.value
    })
  },
  //这个是主要的，改变选项即会触发
  bindMultiPickerColumnChange: function (e) {
    console.log('修改的列为', e.detail.column, '，值为', e.detail.value);
    var multiArray = this.data.multiArray;
    var multiIndex = this.data.multiIndex;
    multiIndex[e.detail.column] = e.detail.value;
    switch (e.detail.column) {
      case 0:		//改变第一列
        console.log(multiIndex);
        multiIndex[1] = 0;	//将二、三列的index设为0，即第一个值
        multiIndex[2] = 0;
        //设置二、三列的列表
        multiArray[1] = this.data.objectArrayDiseaseData[multiIndex[0]].nextList;
        multiArray[2] = this.data.objectArrayDiseaseData[multiIndex[0]].nextList[0].nextList;
        console.log(multiIndex);
        break;
      case 1:		//改变第二列
        console.log(multiIndex);
        multiIndex[2] = 0;
        //设置第三列列表
        multiArray[2] = this.data.objectArrayDiseaseData[multiIndex[0]].nextList[multiIndex[1]].nextList;
        console.log(multiIndex);
        break;
    }
    this.setData({		//将设置好的列表和选项index赋值
      multiArray: multiArray,
      multiIndex: multiIndex,
      //okr_id: this.data.objectArrayDiseaseData[multiIndex[0]].nextList[multiIndex[1]].nextList[multiIndex[2]].okr_id
    });
    //这里可以获取到最后一列选项对应的okr_id
	console.log(this.data.objectArrayDiseaseData[multiIndex[0]].nextList[multiIndex[1]].nextList[multiIndex[2]].okr_id)
  }
})